package com.example.football.controller;

import com.example.football.pojo.Peopleliketeam;
import com.example.football.pojo.Peopleschedule;
import com.example.football.service.PeopleliketeamService;
import com.example.football.service.PeoplescheduleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class PeoplescheduleController {
    @Resource
    private PeoplescheduleService cc;

    //全查
    @RequestMapping("peopleschedulelist")
    public String queryAll(Model model) {
        List<Peopleschedule> list = cc.queryAll();
        //存入model
        model.addAttribute("list", list);
        //控制跳转

        return "peopleschedulelist";
    }

    @RequestMapping("removeByPeoplescheduleid")
    public String removeByPeoplescheduleid(Integer id) {
        try {
            cc.removeByPeoplescheduleid(id);
            return "redirect:/peopleschedulelist";
        } catch (Exception e) {
            return "error";
        }
    }

    @PostMapping("findByPeopleid")
    public String findByPeopleid(String peopleid, Model model){
        List<Peopleschedule> list = cc.queryByPeopleid(peopleid);
        //存入model
        model.addAttribute("list", list);
        return "peopleschedulelist";
    }



    @RequestMapping("addPeopleschedulePage")
    public String addPeopleschedulePage() {
        return "addpeopleschedule";
    }

    @RequestMapping("addPeopleschedule")
    public String addPeopleschedule(Peopleschedule peopleschedule) {
        try {
            cc.addPeopleschedule(peopleschedule);
            return "redirect:/peopleschedulelist";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }



    @GetMapping("findById5")
    public String findById(Integer id, Model model){
        Peopleschedule list = cc.queryById(id);
        //存入model
        model.addAttribute("list", list);
        return "updatepeopleschedule";
    }

    //数据修改
    @PostMapping("updatePeopleschedule")
    public String changePeopleschedule(Peopleschedule peopleschedule) {
        try {
            cc.changePeopleschedule(peopleschedule);
            return "redirect:/peopleschedulelist";
        } catch (Exception e) {
            return "error";
        }
    }
}
